# -*- coding: UTF-8 -*-

import lda_model
import web_apis
import mashups
import user
import similar_word_model
import preprocess
from gensim.corpora import Dictionary
import neo4jtest

def get_topn_similar_api(mashup_name, mashups: mashups.Mashups, apis: web_apis.Web_APIs, users: user.User, kg:neo4jtest.MashupKnowledgeGraph):
    # mashup = mashups.mashup_dict[mashup_name]
    # category = [] if 'category' not in mashup else mashup['category']
    # user = [] if 'user' not in mashup else mashup['user']
    # invoke_api = [] if 'invoke_api' not in mashup else mashup['invoke_api']
    # latent_topic = [] if 'latent_topic' not in mashup else mashup['latent_topic']

    mashup_id = kg.get_node_id(data_type='Mashup', data_name=mashup_name)
    api_ids = kg.remove_api_invoke(mashup_name=mashup_name)
    
    print(kg.probe_sim(node_id=mashup_id, topk=10, c=0.6, r=3, l=1))

    kg.recover_api_invoke(mashup_name=mashup_name, api_id_list=api_ids)    
    

        

    # indexes = topic_model.get_topn_similar_doc(description)
    # dic = {}
    # for inx in indexes:
    #     i = train_set[inx]
    #     name = mashups.names[i]
    #     apis = mashups.api_list[i]
    #     # print(name, apis)
    #     for api in apis:
    #         if api in dic:
    #             dic[api] = dic[api] + 1
    #         else:
    #             dic[api] = 1
    # top_sims = sorted(dic.items(), key=lambda item: -item[1])
    # if len(top_sims) >= topn: 
    #     top_sims = top_sims[:topn]
    # res = {}
    # for item in top_sims:
    #     res[item[0]] = item[1]
    # return res
        


if __name__ == '__main__':
    # ma = mashups.Mashups()
    # ma.train_topic_model()
    # wa = web_apis.Web_APIs()
    # us = user.User()
    ma=None
    wa=None
    us=None
    kg = neo4jtest.MashupKnowledgeGraph("neo4j://localhost:7687", "neo4j", "hahaha")

    query = 'renttoownquest'
    
    get_topn_similar_api(query, ma, wa, us, kg)
    